<?php
if (!defined('IN_WONDERSHARE'))
{
die('Hacking attempt');
}
require('./classes/module/module_faq_index.php');
class FaqIndexControl
{
	var $faq_Index_m;
	function __construct()
	{
	
		$this->faq_index_m = new FaqIndexModule();
	}


	/**
	* 增加或者修改comment
	*
	* @param   string      $type            操作类型
	* @param   array       $operate_array     操作数组
	* @return  int
	*/
	function  operate_comment($type =  '' ,$operate_array = null)
	{
		$sql = " UPDATE faq_index_recommend  SET re_category_id = '{$operate_array['re_category_id']}',re_product_id  = '{$operate_array['re_product_id']}',
		update_time = UNIX_TIMESTAMP(),update_user = '".$_SESSION['AName']."' WHERE re_id = ".$operate_array['re_id']." ";
		return $this->faq_index_m->change_info($sql);	 	
	}

	/**
	* 得到首页信息
	*
	* @param   string     $type       类型（list为列表 不带搜索 而 list_s 在列表 带有搜索）
	* @param   INT        $re_id       ID
	* @param   INT        $webType    网站类型
	* @return  array
	*/
	function  get_index_info($type,$re_id = 0,$webType = 1)
	{
		$where_str = ' WHERE  web_type = '.$webType;
		if($type == 'edit')
		{
			$where_str = 'WHERE re_id = '.$re_id;	 
		}
		$sql = "SELECT re_id,re_category_id,re_product_id ,update_user ,
		IF(update_time > 0, FROM_UNIXTIME(update_time, '%Y-%m-%d %H:%s'), '') 
		update_time FROM  faq_index_recommend $where_str  LIMIT 1";
		$index_info = $this->faq_index_m->get_index_info($sql);
		$index_info[0]['arr_category'] = $this->get_index_category($index_info[0]['re_category_id']);
		$index_info[0]['arr_product'] = $this->get_index_product($index_info[0]['re_product_id'],$webType);
		return $index_info;
	
	}
	/**
	* 得到推荐的分类名称
	* @param   string     $re_category_str_id       以逗号隔开的推荐分类首页ID
	* @return  array
	*/
	function  get_index_category($re_category_str_id = '')
	{
		if(!empty($re_category_str_id))
		{
			$sql = 'SELECT type_name FROM faq_type WHERE FIND_IN_SET(type_id,"'.$re_category_str_id.'")  ';
			return $this->faq_index_m->get_index_info($sql);
		}else
		{
			$sql = 'SELECT type_name,type_id FROM faq_type  ';
			return $this->faq_index_m->get_index_info($sql);
		}
	}
	/**
	* 得到推荐的ws产品名称
	* @param   string     $re_product_str_id       以逗号隔开的推荐产品首页ID
	* @param   INT        $webType    网站类型
	* @return  array
	*/
	function  get_index_product($re_product_str_id = '' , $webType = 1)
	{
		if(!empty($re_product_str_id))
		{
			$sql = 'SELECT product.product_name FROM won_product,product WHERE won_product.won_product_id = product.product_id AND 
			FIND_IN_SET(won_product.id,"'.$re_product_str_id.'") AND won_product.web_type = '.(int)$webType;
			return $this->faq_index_m->get_index_info($sql);
		}else
		{
			return array();
		}
	}


}
?>